#!/bin/bash

source utils.sh

read -p "是否安装 Vim? [Y/n]" i_vim
read -p "是否安装 Golang? [Y/n]" i_go
read -p "是否安装 Java? [Y/n]" i_java
read -p "是否安装 Nginx? [Y/n]" i_nginx
read -p "是否安装 Docker? [Y/n]" i_docker
if [ "$i_docker" != "n" ]; then
	read -p "是否安装Mysql? [Y/n]" i_mysql
fi
read -p "是否安装逻辑语言? [Y/n]" i_prolog
read -p "是否安装监控测试工具? [Y/n]" i_test
read -p "是否安装图形工具? [Y/n]" i_image

# vim
if [ "$i_vim" != "n" ]; then
	# 编辑器
	sudo apt install -y \
		vim \
		ctags
			# vimrc
			if cover ~/.vim_runtime; then
				git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
				sh ~/.vim_runtime/install_awesome_vimrc.sh
			fi
			# vim 配置
			if cover ~/.vim_runtime/my_configs.vim; then
				ln -s ~/.dotfiles/.vim_runtime/my_configs.vim ~/.vim_runtime/my_configs.vim
			fi
fi

# web、代理
if [ "$i_nginx" != "n" ]; then
	sudo apt install -y nginx
fi

# 测试
if [ "$i_test" != "n" ]; then
	# ab 测试
	sudo apt install -y apache2-utils
	# 命令行系统监视工具
	sudo apt install -y glances
fi

# 逻辑语言
if [ "$i_prolog" != "n" ]; then
	sudo apt install -y swi-prolog
fi

# 容器
if [ "$i_docker" != "n" ]; then
	sudo apt install -y docker.io
	# 用户加入到用户组
	sudo usermod -aG docker $USER
	# 重启
	sudo systemctl restart docker
	# 给docker.sock添加权限
	sudo chmod a+rw /var/run/docker.sock
	# mysql
	if [ "$i_mysql" != "n" ]; then
		docker pull mysql
	fi
fi

# java
if [ "$i_java" != "n" ]; then
	curl -s "https://get.sdkman.io" | bash
	source "~/.sdkman/bin/sdkman-init.sh"
	sdk install java 20.3.0.r8-grl
fi

# golang
if [ "$i_go" != "n" ]; then
	# gvm 需要
	sudo apt install -y bison
	# go
	sudo apt install -y golang
	# gvm
	if cover ~/.gvm; then
		sh -c "$(wget -O- https://gitee.com/amintong/gvm/raw/master/binscripts/gvm-installer)"
		source ~/.gvm/scripts/gvm
	fi

	# 安装
	gvm install go1.18.1 -B
	gvm use go1.18.1 --default

	# 代理
	go env -w GO111MODULE=on
	go env -w GOPROXY=https://goproxy.io,direct
	# 国内验证
	go env -w GOSUMDB=sum.golang.google.cn
	# protobuf
	sudo snap install protobuf --classic
	# 代码检查
	go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
	# 必备软件
	go install golang.org/x/tools/...@latest
	# grpc
	go install google.golang.org/grpc@latest
	# 容器
	go install github.com/google/wire/cmd/wire@latest
	# 生成go语言UML图
	go install github.com/jfeliu007/goplantuml/cmd/goplantuml@latest
	go install github.com/seamia/protodot@latest
	# mock
	go install github.com/golang/mock/mockgen@v1.6.0
	# swagger API定义
	# go get github.com/go-swagger/go-swagger/cmd/swagger
	# 私货 自己开发的工具
	# go get gitee.com/xuender/kits/cmd/...
fi

# 图形处理
if [ "$i_image" != "n" ]; then
	# dot
	sudo apt install -y graphviz
fi

# 创建工作目录
mkdir -p ~/work

# 构建工具
sudo apt install -y make
# 编译套件
sudo apt install -y build-essential
# git 扩展
sudo apt install -y git-extras
# 中文 man
sudo apt install -y manpages-zh
# 脚本检查
sudo apt install -y shellcheck
# 代码搜索
sudo apt install -y silversearcher-ag

# 代码格式化规则
if cover ~/.editorconfig; then
	ln -s ~/.dotfiles/.editorconfig ~/.editorconfig
fi
